<?php

use Hyperf\Database\Schema\Schema;
use Hyperf\Database\Schema\Blueprint;
use Hyperf\Database\Migrations\Migration;

class CreateMomentCommentTable extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('moment_comment', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('user_id')->comment('用户ID');
            $table->integer('moment_id')->comment('动态ID');
            $table->string('content', 500)->default('')->comment('评论内容');
            $table->integer('commented_id')->default(0)->comment('回复的评论ID');
            $table->integer('parent_comment_id')->default(0)->comment('父级评论ID');
            $table->integer('commented_user_id')->default(0)->comment('回复的评论用户ID');
            $table->integer('like_num')->default(0)->comment('点赞数');
            $table->tinyInteger('top')->default(0)->comment('是否top热门评论');
            $table->timestamps();
            $table->tinyInteger('flag')->default(1)->comment('状态：0-无效，1-有效');
            $table->index('user_id', 'user_id');
            $table->index('moment_id', 'moment_id');
            $table->index(['user_id', 'moment_id'], 'user_moment_id');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('moment_comment');
    }
}
